<template>
	<view class="bottomBox">
		<view class="selectedBox">
			<view class="price" @click="openList">
				<image class="jt" :src="imgUrlPrefix+'static/images/sjt.png'" mode="widthFix"></image>
				￥<text class="num">{{totalPrice}}</text>
			</view>
		</view>
		<view class="btn" @click="goNext">订购</view>
		<view class="selectList" v-if="show">
			<view class="item" v-for="dt in goods" :key="dt.id">
				<view class="imgbox">
					<image class="minsp" :src="dt.imageUrl" mode="aspectFill"></image>
				</view>
				<view class="con">
					<view class="title">{{dt.name}}</view>
					<view class="price">￥
						<text class="ph" v-if="orderInfo.orderType==1">{{dt.unitPrice}}</text> 
						<text class="ph" v-else-if="orderInfo.orderType==2">{{dt.price}}</text> 
					</view>
				</view>
				<view class="numbox">
					<number-selector v-model="dt.quantity" @onchange="change"/>
				</view>
			</view>
		</view>
	</view>
	<view class="bdgbshadow" v-if="show" @click="openList"></view>
</template>

<script>
	import {defineComponent,reactive,toRefs,onMounted,getCurrentInstance,computed} from 'vue'
	import {onLoad,onShow} from '@dcloudio/uni-app'
	import { useStore } from 'vuex'
	import numberSelector from "@/components/numberSelector/numberSelector.vue"
	export default defineComponent({
		components:{
			numberSelector
		},
		props:{
		
		},
		setup(props,context) {
			const store = useStore()
			const {proxy} = getCurrentInstance()
			
			const state = reactive({
				imgUrlPrefix:getApp().globalData.imgUrlPrefix,
				show:false,
				goods:computed(()=>store.state.base.goods), // 选择的商品
				orderInfo:computed(()=>store.state.base.orderInfo), 
				totalPrice:0
			})
			
			state.totalPrice = computed(()=>{
				//console.log("goods:",state.goods)
				if(state.goods.length==0) {
					return 0
				}
				let total = 0
				state.goods.forEach(item =>{
					if(state.orderInfo.orderType==1){ // 商城类
						total += (item.unitPrice*item.quantity)
					}else if(state.orderInfo.orderType==2){ // 服务类
						total += (item.price*item.quantity)
					}
					
				})
				//const total = state.goods.reduce(function(total,item){return total+item.unitPrice},0)
				return total.toFixed(2)
			})
			
			onMounted(()=>{
				
			})
			
			const openList = ()=>{
				state.show = !state.show
			}
			
			const goNext = ()=>{
				context.emit('onclick')
			}
			
			const change = (num)=>{
				if(num == 0) {
					store.commit('base/del_goods')
				} 
			}
			
			return {
				...toRefs(state),
				openList,
				goNext,
				change
			}
		}
	})
</script>

<style lang="scss" scoped>
	.bdgbshadow{
		position: fixed;
		z-index: 900;
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
		background: rgba(0,0,0,0);
	}
	.bottomBox{
		//display: flex;
		position: relative;
		z-index: 910;
		background: #fff;
		height: 90rpx;
		border-bottom:1px solid #f8f8f8;
		padding: 0 30rpx;
		.selectedBox{
			//flex: 1;
			float: left;
			line-height: 90rpx;
			.price{
				display: flex;
				font-size: 26rpx;
				font-weight: 600;
				color: #ff1b1b;
				.num{
					font-size: 36rpx;
				}
				.jt{
					width: 50rpx;
					height: auto;
					margin: 20rpx 0 0 0;
				}
			}
		}
		.btn{
			float: right;
			width: 150rpx;
			height: 60rpx;
			line-height: 60rpx;
			background: #fba70e;
			border-radius:30rpx;
			font-size: 28rpx;
			font-weight: 600;
			text-align: center;
			margin: 15rpx 0 0 0;
		}
		.selectList{
			position: absolute;
			z-index: 910;
			background: #fff;
			width: 100%;
			//min-height: 200rpx;
			bottom: 90rpx;
			left: 0;
			box-shadow: 0 -10rpx 10rpx #e8e3d8;
			.item{
				display: flex;
				padding: 10rpx 30rpx;
				border-bottom:1px solid #f8f8f8;
				.imgbox{
					width: 80rpx;
					height: 80rpx;
					border-radius:15rpx ;
					overflow: hidden;
					.minsp{
						display: block;
						width: 100%;
						height: 100%;
					}
				}
				.con{
					flex: 1;
					width: 0;
					padding: 0 20rpx;
					.title{
						height: 50rpx;
						white-space: nowrap;
						text-overflow: ellipsis;
						overflow: hidden;
						word-break: break-all;
						font-size: 28rpx;
						font-weight: 600;
					}
					.price{
						font-size: 24rpx;
						.ph{
							font-size: 28rpx;
							color: #ff0000;
							font-weight: 600;
						}
					}
				}
				.numbox{
					width: 240rpx;
				}
			}
		}
	}
</style>
